﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PMisuseAn.io;

namespace PMisuseAn
{
    /// <summary>
    /// Interaction logic for AddConstraintWindow.xaml
    /// </summary>
    public partial class AddConstraintWindow : Window
    {
        AddActorAttributeWindow aaaw_ = null;
        Attribute source_attribute_ = null;
        AddImpliedFromToAttributeWindow aiftaw_ = null;
        public AddConstraintWindow(AddActorAttributeWindow aaaw, Attribute source_attribute)
        {
            InitializeComponent();
            aaaw_ = aaaw;
            source_attribute_ = source_attribute;
            constraint_att.Text = source_attribute_.name;
            constraint_att.IsEnabled = false;
        }

        public AddConstraintWindow(AddImpliedFromToAttributeWindow aiftaw, Attribute source_attribute)
        {
            InitializeComponent();
            aiftaw_ = aiftaw;
            source_attribute_ = source_attribute;
            constraint_att.Text = source_attribute_.name;
            constraint_att.IsEnabled = false;

        }

        private void addConstraint_b_Click(object sender, RoutedEventArgs e)
        {
            string attribute = constraint_att.Text;
            
            string domains_ = constraint_dom.Text;
            domains_.Trim();
            string[] domains = domains_.Split(',');
            for (int i = 0; i < domains.Length; i++)
            {
                source_attribute_.addDomain(domains[i].Trim());
                MisUseAnObjectsDB.addAttributeDomain(source_attribute_, domains[i].Trim(), MainWindow.clusterName);
            }

            if(aaaw_ != null)
                aaaw_.reloadAttributeDomainList(source_attribute_);
            //if (aiftaw_ != null)
            //    aiftaw_.reloadAttributeDomainList(source_attribute_);
            this.Close();
        }
    }
}
